package cn.hfatec.shms.system.notice.service;

import java.util.List;
import java.util.HashMap;


import cn.hfatec.shms.advice.annotation.MysqlDataSource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.hfatec.base.BaseDao;
import cn.hfatec.Page;
import cn.hfatec.Table;
import cn.hfatec.shms.system.notice.model.Notice;
import cn.hfatec.shms.system.notice.dao.NoticeDao;
import cn.hfatec.shms.system.notice.model.NoticeParams;

import javax.annotation.Resource;



/**
 *
 * @author hfatec
 * @version 1.0
 *
 * the JAVA code is generate by middlegen
 *
 */
@Service("NoticeService")
public class NoticeService {

    public static final String BEAN_ID = "NoticeService";

    //注入Dao层
    @Resource(name = "NoticeDao")
    private NoticeDao noticeDao;

    //注入BaseDao
    @Resource(name = "BaseDao")
    private BaseDao baseDao;

    /**
     *
     * 查询数据
     *
     * @param noticeParams
     * @param page
     *
     */
    @Transactional
    @MysqlDataSource
    public Table queryNoticeTable(NoticeParams noticeParams, Page page){

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("params", noticeParams);
        return baseDao.queryTableByPage("queryNotice", params, page);
    }

    /**
     *
     * 查询对应用户的所有数据
     *
     * @param noticeParams
     *
     */
    @Transactional
    @MysqlDataSource
    public List queryNoticeList(NoticeParams noticeParams){
        return noticeDao.queryNotice(noticeParams);
    }
    /**
     *
     * 插入数据
     * @param notice
     *
     */
    @Transactional
    @MysqlDataSource
    public void saveNotice(Notice notice) {
        if(notice.getId() != null) {
            Notice result = getNotice(notice.getId());
            if(result != null) {
                noticeDao.update(notice);
            } else {
                noticeDao.insert(notice);
            }
        } else {
            noticeDao.insert(notice);
        }
    }

    /**
     *
     * 删除数据
     * @param id
     *
     */
    @Transactional
    @MysqlDataSource
    public void deleteNotice(Integer id) {

        noticeDao.delete(id);
    }

    /**
     *
     * 删除数据
     * @param noticeList
     *
     */
    @Transactional
    @MysqlDataSource
    public void deleteNoticeBatch(List<String> noticeList) {
        for(String id : noticeList) {
            deleteNotice(Integer.valueOf(id));
        }
    }

    /**
     *
     * 根据ID获取数据
     * @param id
     *
     */
    @Transactional
    @MysqlDataSource
    public Notice getNotice(Integer id) {

        return noticeDao.getNoticeById(id);
    }
}